package study.itheima.myfilter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
//过滤一切请求和转发
@WebFilter(value = "/*",dispatcherTypes = {DispatcherType.REQUEST,DispatcherType.FORWARD})
public class FilterPrac1 implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("UTF-8");
        servletResponse.setContentType("Text/Html;charset=UTF-8");
        String username = servletRequest.getParameter("username");
        if (username.contains("admin")) {
            filterChain.doFilter(servletRequest, servletResponse);
        }else {
            servletResponse.getWriter().write("权限不够");
        }
    }
}
